export const downloadContentType = [
    'application/msword',
    'application/msword',
    'application/vnd.ms-excel',
    'application/x-msdownload',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    '.csv',
    'application/octet-stream'
]
export const previewContentType = ['image/jpeg', 'image/gif', 'application/pdf']

export function getUUID() {
    return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = (Math.random() * 16) | 0
        const v = c === 'x' ? r : (r & 0x3) | 0x8
        return v.toString(16)
    })
}

export const createArray = (max: number) => {
    let arr = [];
    for (let i = 0; i <= max; i++) {
        arr[i] = i;
    }
    return arr;
}
export const formatDateTime = (date: string | Date, format: string) => {
    if (date) {
        if (typeof date === 'string') {
            date = date.replace(/-/g, '/')
        }
        if (typeof date === "string") {
            date = new Date(Date.parse(date));
        }
        if (typeof date === 'number') {
            date = new Date(date)
        }
        let y = date.getFullYear();
        let m: string | number = date.getMonth() + 1;
        m = m < 10 ? '0' + m : m;
        let d: string | number = date.getDate();
        d = d < 10 ? '0' + d : d;
        let h: string | number = date.getHours();
        h = h < 10 ? '0' + h : h;
        let minute: string | number = date.getMinutes();
        minute = minute < 10 ? '0' + minute : minute;
        let second = date.getSeconds();
        // @ts-ignore
        second = second < 10 ? '0' + second : second;
        if (!format) {
            format = 'YYYY-MM-DD hh:mm:ss';
        }
        if (format.indexOf('YYYY') >= 0 || format.indexOf('yyyy') >= 0) {
            format = format.replace(/YYYY/g, String(y));
            format = format.replace(/yyyy/g, String(y));
        }
        if (format.indexOf('MM') >= 0) {
            format = format.replace(/MM/g, String(m));
        }
        if (format.indexOf('DD') >= 0 || format.indexOf('dd') >= 0) {
            format = format.replace(/DD/g, String(d));
            format = format.replace(/dd/g, String(d));
        }
        if (format.indexOf('HH') >= 0 || format.indexOf('hh') >= 0) {
            format = format.replace(/hh/g, String(h));
            format = format.replace(/HH/g, String(h));
        }
        if (format.indexOf('mm') >= 0) {
            format = format.replace(/mm/g, String(minute));
        }
        if (format.indexOf('SS') >= 0 || format.indexOf('ss') >= 0) {
            format = format.replace(/ss/g, String(second));
            format = format.replace(/SS/g, String(second));
        }
        return format;
    } else {
        return '';
    }
}

export const arrayDeDuplication = (obj: any[], key: string | number) => {
    for(let i=0; i<obj.length; i++){
        for(let j =obj.length - 1; j > 0; j--){
            if(obj[i][key] ==  obj[j][key] && i != j){
                obj.splice(j, 1);
            }
        }
    }
}
